<?php
/* 	These code was generated using phpCIGen v 0.1.b (24/06/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id

	+ Module  		: t_payment View
	+ Description	: For record view
	+ Filename 		: v_t_payment.php
 	+ creator  		: 
 	+ Created on 06/Mar/2012 12:35:49

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */
var t_payment_DataStore;
var t_payment_ColumnModel;
var t_payment_ListEditorGrid;
var t_payment_saveForm;
var t_payment_searchForm;
var t_payment_searchWindow;
var t_payment_SelectedRow;
var t_payment_ContextMenu;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Export Excel";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Lanjut Data";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (hmtl)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

/* declare variable here for Field*/
var payment_idField;
var t_bill_idField;
var payment_dateField;
var payment_typeField;
var payment_valueField;
var payment_noteField;
/* For search form */
var payment_idSearchField;
var t_bill_idSearchField;
var payment_dateSearchField;
var payment_typeSearchField;
var payment_valueSearchField;
var payment_noteSearchField;

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */

  	/* Function for Saving inLine Editing */
	function t_payment_inline_update(oGrid_event){

	var patt=new RegExp("U");
	if(patt.test(PERMISSION)==false){

		Ext.MessageBox.show({
		   title: 'Warning',
		   msg: FAILED_PERMISSION,
		   buttons: Ext.MessageBox.OK,
		   animEl: 'security',
		   icon: Ext.MessageBox.WARNING
		});

	}else{

		var payment_id_update=null;
		var t_bill_id_update=null;
		var payment_date_update_date="";
		var payment_type_update=null;
		var payment_value_update=null;
		var payment_note_update=null;

		if(oGrid_event.record.data.payment_id!== null){payment_id_update = oGrid_event.record.data.payment_id;}
		if(oGrid_event.record.data.t_bill_id!== null){t_bill_id_update = oGrid_event.record.data.t_bill_id;}
	 	if(oGrid_event.record.data.payment_date!== ""){payment_date_update_date =oGrid_event.record.data.payment_date.format('Y-m-d');}
		if(oGrid_event.record.data.payment_type!== null){payment_type_update = oGrid_event.record.data.payment_type;}
		if(oGrid_event.record.data.payment_value!== null){payment_value_update = oGrid_event.record.data.payment_value;}
		if(oGrid_event.record.data.payment_note!== null){payment_note_update = oGrid_event.record.data.payment_note;}

		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_t_payment&m=get_action',
			params: {
				payment_id	:payment_id_update,
				t_bill_id	:t_bill_id_update,
				payment_date	: payment_date_update_date,
				payment_type	:payment_type_update,
				payment_value	:payment_value_update,
				payment_note	:payment_note_update,
				task: "UPDATE"
			},
			success: function(response){
				var result=eval(response.responseText);
				switch(result){
					case 1:
						t_payment_DataStore.commitChanges();
						t_payment_DataStore.reload();
						break;
					default:
						Ext.MessageBox.show({
						   title: 'Warning',
						   msg: FAILED_SAVE,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'save',
						   icon: Ext.MessageBox.WARNING
						});
						break;
				}
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
				   title: 'Error',
				   msg: FAILED_CONNECTION,
				   buttons: Ext.MessageBox.OK,
				   animEl: 'database',
				   icon: Ext.MessageBox.ERROR
				});
			}
		});

		}
	}
  	/* End of Function */

  	/* Function for add and edit data form, open window form */
	function t_payment_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

		if(is_t_payment_form_valid()){
			var payment_id_field=null;
			var t_bill_id_field=null;
			var payment_date_field_date="";
			var payment_type_field=null;
			var payment_value_field=null;
			var payment_note_field=null;

			if(payment_idField.getValue()!== null){payment_id_field = payment_idField.getValue();}
			if(t_bill_idField.getValue()!== null){t_bill_id_field = t_bill_idField.getValue();}
			if(payment_dateField.getValue()!== ""){payment_date_field_date = payment_dateField.getValue().format('Y-m-d');}
			if(payment_typeField.getValue()!== null){payment_type_field = payment_typeField.getValue();}
			if(payment_valueField.getValue()!== null){payment_value_field = payment_valueField.getValue();}
			if(payment_noteField.getValue()!== null){payment_note_field = payment_noteField.getValue();}

			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_t_payment&m=get_action',
				params: {
					payment_id	: payment_id_field,
					t_bill_id	: t_bill_id_field,
					payment_date	: payment_date_field_date,
					payment_type	: payment_type_field,
					payment_value	: payment_value_field,
					payment_note	: payment_note_field,
					task: post2db
				},
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
							t_payment_DataStore.reload();
							t_payment_reset_form();
							break;
						default:
							Ext.MessageBox.show({
							   title: 'Warning',
							   msg: FAILED_SAVE,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'save',
							   icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});

		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_VALID_FORM,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}

		}
	}
 	/* End of Function */

  	/* Function for get PK field */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return t_payment_ListEditorGrid.getSelectionModel().getSelected().get('payment_id');
		else
			return 0;
	}
	/* End of Function  */

	/* Reset form before loading */
	function t_payment_reset_form(){
		post2db="CREATE";
		payment_idField.reset();
		payment_idField.setValue(null);
		t_bill_idField.reset();
		t_bill_idField.setValue(null);
		payment_dateField.reset();
		payment_dateField.setValue(null);
		payment_typeField.reset();
		payment_typeField.setValue(null);
		payment_valueField.reset();
		payment_valueField.setValue(null);
		payment_noteField.reset();
		payment_noteField.setValue(null);
	}
 	/* End of Function */

	/* setValue to EDIT */
	function t_payment_set_form(){
		payment_idField.setValue(t_payment_ListEditorGrid.getSelectionModel().getSelected().get('payment_id'));
		t_bill_idField.setValue(t_payment_ListEditorGrid.getSelectionModel().getSelected().get('t_bill_id'));
		payment_dateField.setValue(t_payment_ListEditorGrid.getSelectionModel().getSelected().get('payment_date'));
		payment_typeField.setValue(t_payment_ListEditorGrid.getSelectionModel().getSelected().get('payment_type'));
		payment_valueField.setValue(t_payment_ListEditorGrid.getSelectionModel().getSelected().get('payment_value'));
		payment_noteField.setValue(t_payment_ListEditorGrid.getSelectionModel().getSelected().get('payment_note'));
	}
	/* End setValue to EDIT*/

	/* Function for Check if the form is valid */
	function is_t_payment_form_valid(){
		return (true  																								);
	}
  	/* End of Function */

  	/* Function for Displaying  create Window Form */
	function display_form_window(){
			post2db='CREATE';
			msg='created';
			t_payment_reset_form();
	}
  	/* End of Function */

  	/* Function for Delete Confirm */
	function t_payment_confirm_delete(){
		// only one t_payment is selected here
		if(t_payment_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, t_payment_delete);
		} else if(t_payment_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, t_payment_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */

	/* Function for Update Confirm */
	function t_payment_confirm_update(){
		/* only one record is selected here */
		if(t_payment_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			t_payment_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */

  	/* Function for Delete Record */
	function t_payment_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = t_payment_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(i = 0; i< t_payment_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.payment_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_payment&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							t_payment_DataStore.reload();
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
  	/* End of Function */

	/* Function for Retrieve DataStore */
	t_payment_DataStore = new Ext.data.Store({
		id: 't_payment_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_payment&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'payment_id'
		},[
			{name: 'payment_id', type: 'int', mapping: 'payment_id'},			{name: 't_bill_id', type: 'int', mapping: 't_bill_id'},			{name: 'payment_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'payment_date'},			{name: 'payment_type', type: 'string', mapping: 'payment_type'},			{name: 'payment_value', type: 'float', mapping: 'payment_value'},			{name: 'payment_note', type: 'string', mapping: 'payment_note'}		]),
		sortInfo:{field: 'payment_id', direction: "DESC"}
	});
        
        t_bill_DataStore = new Ext.data.Store({
		id: 't_bill_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_t_bill_forpayment',
			method: 'POST'
		}),
		baseParams:{start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'bill_id'
		},[
			{name: 'bill_id', type: 'int', mapping: 'bill_id'},
			{name: 'bill_no', type: 'string', mapping: 'bill_no'}
		]),
		sortInfo:{field: 'bill_no', direction: "ASC"}
	});
	/* End of Function */

  	/* Function for Identify of Window Column Model */
	t_payment_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'Payment Id',
			dataIndex: 'payment_id',
			width: 150,
			sortable: true,
                        hidden: true,
			editor: new Ext.form.NumberField({
				allowDecimals: false,
					allowNegative: false,
				blankText: '0',
				maxLength: 11,
				maskRe: /([0-9]+)$/
			})
		},
		{
			header: 'No Tagihan',
			dataIndex: 't_bill_id',
			width: 150,
			sortable: true,
			editor: new Ext.form.NumberField({
				allowDecimals: false,
					allowNegative: false,
				blankText: '0',
				maxLength: 11,
				maskRe: /([0-9]+)$/
			})
		},
		{
			header: 'Tgl Pembayaran',
			dataIndex: 'payment_date',
			width: 150,
			sortable: true,
			renderer: Ext.util.Format.dateRenderer('Y-m-d'),
			editor: new Ext.form.DateField({
					format: 'Y-m-d'
			})
		},
		{
			header: 'Cara Bayar',
			dataIndex: 'payment_type',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		},
		{
			header: 'Jumlah',
			dataIndex: 'payment_value',
			width: 150,
			sortable: true,
			editor: new Ext.form.NumberField({
				allowDecimals: true,
					allowNegative: false,
				blankText: '0',
				maxLength: 22,
				maskRe: /([0-9]+)$/
			})
		},
		{
			header: 'Catatan',
			dataIndex: 'payment_note',
			width: 150,
			sortable: true,
			editor: new Ext.form.TextArea({
					height: 5
			})
		}	]);

	t_payment_ColumnModel.defaultSortable= true;
	/* End of Function */

    /* Button Control */
    t_payment_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: display_form_window
    });

    t_payment_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_payment_confirm_update
	});

    t_payment_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_payment_confirm_delete
	});

    /*Context Menu Button */

	t_payment_cbtn_update=new Ext.menu.Item({
		text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_payment_editContextMenu
	});

	t_payment_cbtn_delete=new Ext.menu.Item({
		text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_payment_confirm_delete
	});

	/* Declare DataStore and  show datagrid list */
	t_payment_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_payment_ListEditorGrid',
		el: 'fp_t_payment',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: t_payment_DataStore, // DataStore
		cm: t_payment_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 700,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: t_payment_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		t_payment_gbtn_add, '-',
		t_payment_gbtn_update, '-',
		t_payment_gbtn_delete, '-',
		{
			text: BTN_SEARCH_TITLE,
			tooltip: BTN_SEARCH_TOOLTIP,
			iconCls:'icon-search',
			handler: display_form_search_window
		}, '-',
		new Ext.app.SearchField({
			store: t_payment_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						t_payment_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		}),'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: t_payment_reset_search,
			iconCls:'icon-refresh'
		},'-',{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: t_payment_export_excel
		}, '-',{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: t_payment_print
		}
		]
	});
	t_payment_ListEditorGrid.render();
	/* End of DataStore */

	/* Create Context Menu */
	t_payment_ContextMenu = new Ext.menu.Menu({
		id: 't_payment_ContextMenu',
		items: [
		t_payment_cbtn_update,
		t_payment_cbtn_delete,
		'-',
		{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: t_payment_print
		},
		{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: t_payment_export_excel
		}
		]
	});
	/* End of Declaration */

	/* Event while selected row via context menu */
	function ont_payment_ContextMenu(grid, rowIndex, e) {
		e.stopEvent();
		var coords = e.getXY();
		t_payment_ContextMenu.rowRecord = grid.store.getAt(rowIndex);
		grid.selModel.selectRow(rowIndex);
		t_payment_SelectedRow=rowIndex;
		t_payment_ContextMenu.showAt([coords[0], coords[1]]);
  	}
  	/* End of Function */

	/* function for editing row via context menu */
	function t_payment_editContextMenu(){
		//t_payment_ListEditorGrid.startEditing(t_payment_SelectedRow,1);
		t_payment_confirm_update();
  	}
	/* End of Function */

	t_payment_ListEditorGrid.addListener('rowcontextmenu', ont_payment_ContextMenu);
	t_payment_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
	t_payment_ListEditorGrid.on('afteredit', t_payment_inline_update); // inLine Editing Record

	payment_idField= new Ext.form.NumberField({
		id: 'payment_idField',
		fieldLabel: 'Payment Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
                hidden: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
        t_bill_idField= new Ext.form.ComboBox({
		id: 't_bill_idField',
		fieldLabel: 'No Tagihan <font color=red>*</font>',
                emptyText: 'Pilih No Tagihan',
		store: t_bill_DataStore,
		mode: 'remote',
		displayField:'bill_no',
                valueField: 'bill_id',
		allowBlank: false,
		editable: true,
		anchor: '95%',
		pageSize: 15,
		triggerAction: 'all'
	});
	payment_dateField= new Ext.form.DateField({
		id: 'payment_dateField',
		fieldLabel: 'Tgl Pembayaran ',
		format : 'Y-m-d',
		anchor: '95%'
	});
	payment_typeField= new Ext.form.TextField({
		id: 'payment_typeField',
		fieldLabel: 'Cara Bayar ',
		maxLength: 10,
		anchor: '95%'
	});
	payment_valueField= new Ext.form.NumberField({
		id: 'payment_valueField',
		fieldLabel: 'Jumlah ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	payment_noteField= new Ext.form.TextArea({
		id: 'payment_noteField',
		fieldLabel: 'Catatan ',
		maxLength: 100,
		anchor: '95%'
	});


	t_payment_btn_Save=new Ext.Button({
		text: BTN_SAVE,
		handler: t_payment_save
	})
	/* Function for retrieve create Window Panel*/
	t_payment_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' T Payment',
		bodyStyle:'padding:5px',
		autoHeight:true,
		layout:'column',
		width: 700,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_t_payment_save',
		items:[
                        {
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [payment_idField,
                                        t_bill_idField,
                                        payment_dateField ] 
			},
                        {
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [payment_typeField,
                                        payment_valueField,
                                        payment_noteField,new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED })] 
			}
			],
		buttons: [t_payment_btn_Save
			,{
				text: BTN_CANCEL,
				handler: function(){
					t_payment_reset_form();
				}
			}
		]
	});
	/* End  of Function*/


	/* Function for action list search */
	function t_payment_list_search(){

		var payment_id_search=null;
		var t_bill_id_search=null;
		var payment_date_search_date="";
		var payment_type_search=null;
		var payment_value_search=null;
		var payment_note_search=null;

		if(payment_idSearchField.getValue()!==null){payment_id_search=payment_idSearchField.getValue();}
		if(t_bill_idSearchField.getValue()!==null){t_bill_id_search=t_bill_idSearchField.getValue();}
		if(payment_dateSearchField.getValue()!==""){payment_date_search_date=payment_dateSearchField.getValue().format('Y-m-d');}
		if(payment_typeSearchField.getValue()!==null){payment_type_search=payment_typeSearchField.getValue();}
		if(payment_valueSearchField.getValue()!==null){payment_value_search=payment_valueSearchField.getValue();}
		if(payment_noteSearchField.getValue()!==null){payment_note_search=payment_noteSearchField.getValue();}

		t_payment_DataStore.baseParams = {
			task: 'SEARCH',
			payment_id	:	payment_id_search,			t_bill_id	:	t_bill_id_search,			payment_date	:	payment_date_search_date,			payment_type	:	payment_type_search,			payment_value	:	payment_value_search,			payment_note	:	payment_note_search		};

		t_payment_DataStore.reload({params: {start: 0, limit: pageS}});
	}

	/* Function for reset search result */
	function t_payment_reset_search(){
		t_payment_DataStore.baseParams = { task: 'LIST' };
		t_payment_DataStore.reload({params: {start: 0, limit: pageS}});
		t_payment_searchWindow.close();
	};
	/* End of Fuction */

	/* Field for search */
	/* Identify  payment_id Search Field */
	payment_idSearchField= new Ext.form.NumberField({
		id: 'payment_idSearchField',
		fieldLabel: 'Payment Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  t_bill_id Search Field */
	t_bill_idSearchField= new Ext.form.NumberField({
		id: 't_bill_idSearchField',
		fieldLabel: 'T Bill Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  payment_date Search Field */
	payment_dateSearchField= new Ext.form.DateField({
		id: 'payment_dateSearchField',
		fieldLabel: 'Payment Date',
		format : 'Y-m-d'
	});
	/* Identify  payment_type Search Field */
	payment_typeSearchField= new Ext.form.TextField({
		id: 'payment_typeSearchField',
		fieldLabel: 'Payment Type',
		maxLength: 10,
		anchor: '95%'
	});
	/* Identify  payment_value Search Field */
	payment_valueSearchField= new Ext.form.NumberField({
		id: 'payment_valueSearchField',
		fieldLabel: 'Payment Value',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  payment_note Search Field */
	payment_noteSearchField= new Ext.form.TextField({
		id: 'payment_noteSearchField',
		fieldLabel: 'Payment Note',
		maxLength: 100,
		anchor: '95%'
	});

	/* Function for retrieve search Form Panel */
	t_payment_searchForm = new Ext.FormPanel({
		labelAlign: 'left',
		layout:'form',
		bodyStyle:'padding:5px',
		autoHeight:true,
		frame: true,
		width: 500,
		items: [payment_idSearchField,
				t_bill_idSearchField,
				payment_dateSearchField,
				payment_typeSearchField,
				payment_valueSearchField,
				payment_noteSearchField
		 ],
		buttons: [{
				text: BTN_SEARCH,
				handler: t_payment_list_search
			},{
				text: BTN_CANCEL,
				handler: function(){
					t_payment_searchWindow.hide();
				}
			}
		]
	});
    /* End of Function */

	/* Function for retrieve search Window Form, used for andvaced search */
	t_payment_searchWindow = new Ext.Window({
		title: TITLE_FORM_SEARCH+'t_payment',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_t_payment_search',
		items: t_payment_searchForm
	});
    /* End of Function */

  	/* Function for Displaying  Search Window Form */
	function display_form_search_window(){
		if(!t_payment_searchWindow.isVisible()){
			t_payment_searchWindow.show();
		} else {
			t_payment_searchWindow.toFront();
		}
	}
  	/* End Function */

	/* Function for print List Grid */
	function t_payment_print(){
		var searchquery = "";
		var payment_id_print=null;
		var t_bill_id_print=null;
		var payment_date_print_date="";
		var payment_type_print=null;
		var payment_value_print=null;
		var payment_note_print=null;

		if(t_payment_DataStore.baseParams.query!==null){searchquery = t_payment_DataStore.baseParams.query;}
		if(t_payment_DataStore.baseParams.payment_id!==null){payment_id_print = t_payment_DataStore.baseParams.payment_id;}
		if(t_payment_DataStore.baseParams.t_bill_id!==null){t_bill_id_print = t_payment_DataStore.baseParams.t_bill_id;}
		if(t_payment_DataStore.baseParams.payment_date!==""){payment_date_print_date = t_payment_DataStore.baseParams.payment_date;}
		if(t_payment_DataStore.baseParams.payment_type!==null){payment_type_print = t_payment_DataStore.baseParams.payment_type;}
		if(t_payment_DataStore.baseParams.payment_value!==null){payment_value_print = t_payment_DataStore.baseParams.payment_value;}
		if(t_payment_DataStore.baseParams.payment_note!==null){payment_note_print = t_payment_DataStore.baseParams.payment_note;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_payment&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,
			payment_id : payment_id_print,
			t_bill_id : t_bill_id_print,
		  	payment_date : payment_date_print_date,
			payment_type : payment_type_print,
			payment_value : payment_value_print,
			payment_note : payment_note_print,
		  	currentlisting: t_payment_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				window.open('./print/t_payment_printlist.html','t_paymentlist','height=600,width=800,resizable=1,scrollbars=0, menubar=0');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_PRINT,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	/* Enf Function */

	/* Function for print Export to Excel Grid */
	function t_payment_export_excel(){
		var searchquery = "";
		var payment_id_2excel=null;
		var t_bill_id_2excel=null;
		var payment_date_2excel_date="";
		var payment_type_2excel=null;
		var payment_value_2excel=null;
		var payment_note_2excel=null;

		if(t_payment_DataStore.baseParams.query!==null){searchquery = t_payment_DataStore.baseParams.query;}
		if(t_payment_DataStore.baseParams.payment_id!==null){payment_id_2excel = t_payment_DataStore.baseParams.payment_id;}
		if(t_payment_DataStore.baseParams.t_bill_id!==null){t_bill_id_2excel = t_payment_DataStore.baseParams.t_bill_id;}
		if(t_payment_DataStore.baseParams.payment_date!==""){payment_date_2excel_date = t_payment_DataStore.baseParams.payment_date;}
		if(t_payment_DataStore.baseParams.payment_type!==null){payment_type_2excel = t_payment_DataStore.baseParams.payment_type;}
		if(t_payment_DataStore.baseParams.payment_value!==null){payment_value_2excel = t_payment_DataStore.baseParams.payment_value;}
		if(t_payment_DataStore.baseParams.payment_note!==null){payment_note_2excel = t_payment_DataStore.baseParams.payment_note;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_payment&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,
			payment_id : payment_id_2excel,
			t_bill_id : t_bill_id_2excel,
		  	payment_date : payment_date_2excel_date,
			payment_type : payment_type_2excel,
			payment_value : payment_value_2excel,
			payment_note : payment_note_2excel,
		  	currentlisting: t_payment_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				win = window.location=('./export2excel.php');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_EXCEL,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	/*End of Function */

	/* Show Hide control for permission */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	if(pattc.test(PERMISSION)==false){
		t_payment_gbtn_add.setVisible(false);
	}else{
		t_payment_gbtn_add.setVisible(true);
	}

	if(pattu.test(PERMISSION)==false){
		t_payment_gbtn_update.setVisible(false);
		t_payment_cbtn_update.setVisible(false);
	}else{
		t_payment_gbtn_update.setVisible(true);
		t_payment_cbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		t_payment_gbtn_delete.setVisible(false);
		t_payment_cbtn_delete.setVisible(false);
	}else{
		t_payment_gbtn_delete.setVisible(true);
		t_payment_cbtn_delete.setVisible(true);
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		t_payment_btn_Save.setVisible(false);
	}else{
		t_payment_btn_Save.setVisible(true);
	}
});
	</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_t_payment_save"></div>
		<div>&nbsp;</div>
		<div id="fp_t_payment"></div>
        <div id="elwindow_t_payment_search"></div>
    </div>
</div>
</body>
</html>